home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Text / Digest-Browser-1.6 Folder / Application / CBrowserApp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-16  |  3.2 KB  |  152 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * CBrowserApp.c
  3.  *
  4.  *    Application methods for a typical application.
  5.  *
  6.  *  Copyright © 1990 Symantec Corporation.  All rights reserved.
  7.  *  Copyright © 1991 Manuel A. Pérez.  All rights reserved.
  8.  *
  9.  *****/
  10.  
  11. #include "CBrowserApp.h"
  12. #include "CBrowserDoc.h"
  13. #include <Commands.h>
  14.  
  15. extern    OSType    gSignature;
  16.  
  17. #define        kExtraMasters        4
  18. #define        kRainyDayFund        20480
  19. #define        kCriticalBalance    20480
  20. #define        kToolboxBalance        20480
  21.  
  22.  
  23. /***
  24.  * IBrowserApp
  25.  ***/
  26.  
  27. void CBrowserApp::IBrowserApp(void)
  28.  
  29. {
  30.     CApplication::IApplication( kExtraMasters, kRainyDayFund, 
  31.                         kCriticalBalance, kToolboxBalance);
  32. }
  33.  
  34. /***
  35.  * SetUpFileParameters
  36.  ***/
  37.  
  38. void CBrowserApp::SetUpFileParameters(void)
  39.  
  40. {
  41.     inherited::SetUpFileParameters();    /* Be sure to call the default method */
  42.  
  43.         /**
  44.          **    sfNumTypes is the number of file types
  45.          **    your application knows about.
  46.          **    sfFileTypes[] is an array of file types.
  47.          **    You can define up to 4 file types in
  48.          **    sfFileTypes[].
  49.          **
  50.          **/
  51.  
  52.     sfNumTypes = 1;
  53.     sfFileTypes[0] = 'TEXT';
  54.  
  55.         /**
  56.          **    Although it's not an instance variable,
  57.          **    this method is a good place to set the
  58.          **    gSignature global variable. Set this global
  59.          **    to your application's signature. You'll use it
  60.          **    to create a file (see CFile::CreateNew()).
  61.          **
  62.          **/
  63.  
  64.     gSignature = 'dbws';
  65. }
  66.  
  67. /***
  68.  * DoCommand - handle about box
  69.  ***/
  70. void CBrowserApp::DoCommand(long theCommand)
  71.  
  72. {
  73.     switch (theCommand) {
  74.         case cmdAbout:
  75.             Alert(1000, NULL);
  76.             break;
  77.  
  78.         default:    inherited::DoCommand(theCommand);
  79.                     break;
  80.     }
  81. }
  82.  
  83. /***
  84.  * OpenDocument
  85.  *
  86.  *    The user chose Open… from the File menu.
  87.  *    In this method you need to create a document
  88.  *    and send it an OpenFile() message.
  89.  *
  90.  *    The macSFReply is a good SFReply record that contains
  91.  *    the name and vRefNum of the file the user chose to
  92.  *    open.
  93.  *
  94.  ***/
  95.  
  96. void CBrowserApp::OpenDocument(SFReply *macSFReply)
  97. {
  98. CBrowserDoc    *theDocument = NULL;
  99.     
  100.     TRY
  101.     {
  102.     
  103.         theDocument = new(CBrowserDoc);
  104.             
  105.             /**
  106.              **    Send your document an initialization
  107.              **    message. The first argument is the
  108.              **    supervisor (the application). The second
  109.              **    argument is TRUE if the document is printable.
  110.              **
  111.              **/
  112.         
  113.         theDocument->IBrowserDoc(this, TRUE);
  114.     
  115.             /**
  116.              **    Send the document an OpenFile() message.
  117.              **    The document will open a window, open
  118.              **    the file specified in the macSFReply record,
  119.              **    and display it in its window.
  120.              **
  121.              **/
  122.         theDocument->OpenFile(macSFReply);
  123.     }
  124.     
  125.     CATCH
  126.     {
  127.         /*
  128.          * This exception handler gets executed if a failure occurred 
  129.          * anywhere within the scope of the TRY block above. Since 
  130.          * this indicates that the document could not be opened, we
  131.          * send it a Dispose message. The exception will propagate up to
  132.          * CSwitchboard's exception handler, which handles displaying
  133.          * an error alert.
  134.          */
  135.          
  136.          if (theDocument) theDocument->Dispose();
  137.     }
  138.     ENDTRY;
  139. }
  140.  
  141. /******************************************************************************
  142.  InitToolbox
  143.  
  144.         Initialize the Macintosh Toolbox
  145.  ******************************************************************************/
  146.  
  147. void    CBrowserApp::InitToolbox(void)
  148. {
  149.     // do nothing, the toolbox is initialized outside of this
  150.     // object, so that we can put up a splash screen
  151. }
  152.